# -*- coding: utf-8 -*-

import scrapy
# import os
from mz_decode import jandan_load_img

from demo.items import DemoItem

class DemoSpider(scrapy.Spider):

    name="demo"

    allowed_domains=['jandan.net']

    start_urls=[]

    def __init__(self, *args, **kwargs):
        
        self.start_urls.append('http://jandan.net/ooxx/page-44')
        
        
        print("\n\n\n")
        print("okokok")
        print("\n\n\n")

    def parse(self,response):
        
        # filename = response.url.split("/")[-2]

        # with open(filename,"wb") as f:
            # f.write(response.body)
        sel = scrapy.selector.Selector(response)
        sites = sel.xpath("//span[@class='img-hash']/text()").extract();
        
        # print("\n\n\n")
        # print(response.body)
        # print("\n\n\n")

        items=[]

        for i in sites:
            
            # 初始化一个 item 实例
            item = DemoItem()
            
            item['encodeLink'] = i
            item["link"] = "http:"+jandan_load_img(i)

            items.append(item)

        # print("\n\n")

        return items

